package com.khoayang.littlefighterchaos.game;

import org.cocos2d.nodes.CCAnimation;
import org.cocos2d.sound.SoundEngine;
import org.w3c.dom.Node;

import android.content.Context;

public abstract class BaseSkill {
	protected String _SkillName;
	protected CCAnimation _Animation;
	protected float _AnimationDelay;
	protected int _Direction;
	private float _Velocity;
	private String _SoundEffect;
	private Context _Context;
	
	public BaseSkill(Context context)
	{
		_Context = context;
	}

	public String get_SkillName() {
		return _SkillName;
	}

	public void set_SkillName(String _SkillName) {
		this._SkillName = _SkillName;
	}

	public CCAnimation get_Animation() {
		return _Animation;
	}

	public void set_Animation(CCAnimation _Animation) {
		this._Animation = _Animation;
	}

	public float get_AnimationDelay() {
		return _AnimationDelay;
	}

	public void set_AnimationDelay(float _AnimationDelay) {
		this._AnimationDelay = _AnimationDelay;
	}

	public void readSkill(Node node){
		for(int i=0; i<node.getChildNodes().getLength(); i++){
			Node nodeTemp = node.getChildNodes().item(i);
			String nodeName = nodeTemp.getNodeName();
			if(nodeName.compareTo("Name") == 0){
				_SkillName = nodeTemp.getTextContent();
			}else if(nodeName.compareTo("Animation") == 0){
				_Animation = readAnimationFromNode(nodeTemp);
			}else if(nodeName.compareTo("AnimationDelay") == 0){
				_AnimationDelay = Float.parseFloat(nodeTemp.getTextContent());
			}else if(nodeName.compareTo("Direction") == 0){
				_Direction = Integer.parseInt(nodeTemp.getTextContent());
			}else if(nodeName.compareTo("Velocity") == 0){
				_Velocity = Float.parseFloat(nodeTemp.getTextContent());
			}else if(nodeName.compareTo("SoundEffect") == 0){
				_SoundEffect = nodeTemp.getTextContent();
				if(_SoundEffect != null){
					if(_SoundEffect.length() > 0){
						int resId = Util.getIDFromRawRes(_SoundEffect, _Context);
						SoundEngine.sharedEngine().preloadEffect(_Context, resId);
					}
				}
			}
			readSpecificAttributeSkill(nodeTemp);
		}
	}

	private CCAnimation readAnimationFromNode(Node node) {
		CCAnimation animation = CCAnimation.animation("");
		for(int i=0; i<node.getChildNodes().getLength(); i++){
			Node nodeTemp = node.getChildNodes().item(i);
			if(nodeTemp.getNodeName().compareTo("Frame") == 0)
				animation.addFrame(nodeTemp.getTextContent());
		}
		return animation;
	}

	protected abstract void readSpecificAttributeSkill(Node nodeTemp);

	public void startAnimation(String name){
		
	}

	public float get_Velocity() {
		return _Velocity;
	}

	public void set_Velocity(float _Velocity) {
		this._Velocity = _Velocity;
	}

	public String get_SoundEffect() {
		return _SoundEffect;
	}

	public void set_SoundEffect(String _SoundEffect) {
		this._SoundEffect = _SoundEffect;
	}
	
	//public BaseSkill clone();
}
